package com.stylefeng.guns.modular.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.stylefeng.guns.modular.util.NumUtil;
import com.stylefeng.guns.modular.area.model.BdapCellInfoMonth;
import com.stylefeng.guns.modular.area.model.BdapCellPopHour;
import com.stylefeng.guns.modular.area.model.BdapCityDistrict;

public class EntityUtil {

	/**
	 * 获取随机小区人口对象
	 * 
	 * @return
	 */
	public static BdapCellPopHour getRandomPopulation() {
		String male = String.valueOf(NumUtil.getRandom(40, 100));
		String female = String.valueOf(NumUtil.getRandom(20, 90));
		String age0 = String.valueOf(NumUtil.getRandom(0, 5));
		String age10 = String.valueOf(NumUtil.getRandom(5, 20));
		String age20 = String.valueOf(NumUtil.getRandom(10, 40));
		String age30 = String.valueOf(NumUtil.getRandom(30, 60));
		String age40 = String.valueOf(NumUtil.getRandom(10, 40));
		String age50 = String.valueOf(NumUtil.getRandom(5, 20));
		String age60 = String.valueOf(NumUtil.getRandom(0, 5));
		String wuHan = String.valueOf(NumUtil.getRandom(30, 40));
		String xiangYang = String.valueOf(NumUtil.getRandom(2, 10));
		String eZhou = String.valueOf(NumUtil.getRandom(2, 10));
		String xiaoGan = String.valueOf(NumUtil.getRandom(2, 10));
		String huangGang = String.valueOf(NumUtil.getRandom(2, 10));
		String huangShi = String.valueOf(NumUtil.getRandom(2, 10));
		String xianNing = String.valueOf(NumUtil.getRandom(2, 10));
		String jingZhou = String.valueOf(NumUtil.getRandom(2, 10));
		String yiChang = String.valueOf(NumUtil.getRandom(2, 10));
		String enShi = String.valueOf(NumUtil.getRandom(2, 10));
		String shiYan = String.valueOf(NumUtil.getRandom(2, 10));
		String suiZhou = String.valueOf(NumUtil.getRandom(2, 10));
		String jingMen = String.valueOf(NumUtil.getRandom(2, 10));
		String jiangHan = String.valueOf(NumUtil.getRandom(2, 10));
		String qianJiang = String.valueOf(NumUtil.getRandom(2, 10));
		String tianMen = String.valueOf(NumUtil.getRandom(2, 10));
		String total = String.valueOf(Integer.parseInt(female) + Integer.parseInt(male));
		BdapCellPopHour bcph = new BdapCellPopHour("", "", total, male, female, age0, age10, age20, age30, age40, age50,
				age60, wuHan, xiangYang, eZhou, xiaoGan, huangGang, huangShi, xianNing, jingZhou, yiChang, enShi,
				shiYan, suiZhou, jingMen, jiangHan, qianJiang, tianMen, "");
		return bcph;
	}

	/**
	 * 合并小区人口对象
	 * 
	 * @param bcphList
	 * @return
	 */
	public static BdapCellPopHour getMergePopulation(List<BdapCellPopHour> bcphList) {
		int male = 0;
		int female = 0;
		int age0 = 0;
		int age10 = 0;
		int age20 = 0;
		int age30 = 0;
		int age40 = 0;
		int age50 = 0;
		int age60 = 0;
		int wuHan = 0;
		int xiangYang = 0;
		int eZhou = 0;
		int xiaoGan = 0;
		int huangGang = 0;
		int huangShi = 0;
		int xianNing = 0;
		int jingZhou = 0;
		int yiChang = 0;
		int enShi = 0;
		int shiYan = 0;
		int suiZhou = 0;
		int jingMen = 0;
		int jiangHan = 0;
		int qianJiang = 0;
		int tianMen = 0;
		int total = 0;
		for (BdapCellPopHour bcph : bcphList) {
			male += Integer.parseInt(bcph.getMale());
			female += Integer.parseInt(bcph.getFemale());
			age0 += Integer.parseInt(bcph.getAge0());
			age10 += Integer.parseInt(bcph.getAge10());
			age20 += Integer.parseInt(bcph.getAge20());
			age30 += Integer.parseInt(bcph.getAge30());
			age40 += Integer.parseInt(bcph.getAge40());
			age50 += Integer.parseInt(bcph.getAge50());
			age60 += Integer.parseInt(bcph.getAge60());
			wuHan += Integer.parseInt(bcph.getWuHan());
			xiangYang += Integer.parseInt(bcph.getXiangYang());
			eZhou += Integer.parseInt(bcph.geteZhou());
			xiaoGan += Integer.parseInt(bcph.getXiaoGan());
			huangGang += Integer.parseInt(bcph.getHuangGang());
			huangShi += Integer.parseInt(bcph.getHuangShi());
			xianNing += Integer.parseInt(bcph.getXianNing());
			jingZhou += Integer.parseInt(bcph.getJingZhou());
			yiChang += Integer.parseInt(bcph.getYiChang());
			enShi += Integer.parseInt(bcph.getEnShi());
			shiYan += Integer.parseInt(bcph.getShiYan());
			suiZhou += Integer.parseInt(bcph.getSuiZhou());
			jingMen += Integer.parseInt(bcph.getJingMen());
			jiangHan += Integer.parseInt(bcph.getJiangHan());
			qianJiang += Integer.parseInt(bcph.getQianJiang());
			tianMen += Integer.parseInt(bcph.getTianMen());
			total += Integer.parseInt(bcph.getTotal());
		}
		BdapCellPopHour newBcph = new BdapCellPopHour("", "", String.valueOf(total), String.valueOf(male),
				String.valueOf(female), String.valueOf(age0), String.valueOf(age10), String.valueOf(age20),
				String.valueOf(age30), String.valueOf(age40), String.valueOf(age50), String.valueOf(age60),
				String.valueOf(wuHan), String.valueOf(xiangYang), String.valueOf(eZhou), String.valueOf(xiaoGan),
				String.valueOf(huangGang), String.valueOf(huangShi), String.valueOf(xianNing), String.valueOf(jingZhou),
				String.valueOf(yiChang), String.valueOf(enShi), String.valueOf(shiYan), String.valueOf(suiZhou),
				String.valueOf(jingMen), String.valueOf(jiangHan), String.valueOf(qianJiang), String.valueOf(tianMen),
				"");
		return newBcph;
	}

	/**
	 * 字符串集合转小区人口对象集合
	 * 
	 * @param stringList
	 * @return
	 */
	public static List<BdapCellInfoMonth> stringListToCellList(List<String> stringList) {
		List<BdapCellInfoMonth> bcimList = new ArrayList<BdapCellInfoMonth>();
		for (String string : stringList) {
			bcimList.add(EntityUtil.stringToCell(string));
		}
		return bcimList;
	}

	/**
	 * 字符串转小区
	 * 
	 * @param string
	 * @return
	 */
	public static BdapCellInfoMonth stringToCell(String string) {
		String[] stringArr = string.split("\t");
		String cityName = stringArr[0];
		String districtName = stringArr[1];
		String lac = stringArr[2];
		String ci = stringArr[3];
		String cellName = stringArr[4];
		String lng = stringArr[5];
		String lat = stringArr[6];
		String time = stringArr[7];
		BdapCellInfoMonth bcim = new BdapCellInfoMonth(cityName, districtName, lac, ci, cellName, lng, lat, time);
		return bcim;
	}

	public static Map<String, List<String>> getCityDistrictMap(List<BdapCityDistrict> cityDistrictList) {
		Map<String, List<String>> cityEntityMap = new HashMap<String, List<String>>();
		Set<String> citySet = new HashSet<String>();
		for (BdapCityDistrict cityDistrict : cityDistrictList) {
			citySet.add(cityDistrict.getCity());
		}
		for (String city : citySet) {
			cityEntityMap.put(city, new ArrayList<String>());
		}
		for (BdapCityDistrict cityDistrict : cityDistrictList) {
			cityEntityMap.get(cityDistrict.getCity()).add(cityDistrict.getDistrict());
		}
		return cityEntityMap;
	}
}
